#include "isa.h"
void updata_cpu_state(uint64_t pc, uint64_t *gpr)
{
#ifdef CONFIG_DIFFTEST
    updata_cpu_reg(gpr);
    cpu_state.pc = pc;
#endif
}
void updata_cpu_reg(uint64_t *gpr)
{
    memcpy(cpu_state.gpr, gpr, 32 * 8);
}
const char *regs_name[] = {
    "$0", "ra", "sp", "gp", "tp", "t0", "t1", "t2",
    "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5",
    "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7",
    "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6"};
void isa_reg_display(CPU_state *cpu)
{
    for (int i = 0; i < 32; i++)
    {
        printf("%-3s:0x%016lx\t", regs_name[i], cpu->gpr[i]);
        if (i % 4 == 3)
            printf("\n");
    }
}
word_t isa_reg_str2val(const char *s, bool *success)
{
    if (strcmp("PC", s) == 0)
    {
        *success = true;
        return cpu_state.pc;
    }
    int i;
    for (i = 0; i < 32; ++i)
    {
        if (strcmp(regs_name[i], s) == 0)
        {
            *success = true;
            break;
        }
    }
    if (i < 32)
    {
        return cpu_state.gpr[i];
    }
    else
        return 0;
}

bool isa_difftest_checkregs(CPU_state *ref, vaddr_t pc)
{
    int ret = memcmp(ref, &cpu_state, sizeof(CPU_state));
    return ret == 0;
}
